<?php

class redirectMeDownComponents extends myComponents{

	public function executeRender()
  {
    $structure = $this->getRoute()->getObject();
    $elements  = Doctrine::getTable('Structure')->findAll();
    $redirect  = '';
    
    foreach($elements as $node) {
      if($node->getId() == $structure->getId()) {
        if($node->getParameter() == 'clients') {
          $descendant = $node->getNode()->getDescendants()->getFirst();
          $redirect   = LinkGen::getInstance(LinkGen::STRUCTURE)->link($descendant->getId());
        }
      }
    }
    
    if($redirect)
      $this->getAction()->redirect($redirect);

		
		  /*if(($menuElement = NavigationMenu::getInstance(NavigationMenu::DEFAULT_MENU)
				->getElement(MenuElement::STRUCTURE_NODE, $this->getObject()->getId()))){


					foreach($menuElement->getSubElements() as $sub){
						if(!$sub->isHidden()){
							$this->getAction()->redirect($sub->getLink());
						}
					}
			}*/
      
      
		
		
		return sfView::NONE;
	}
	
}